//
//  RealmModel.h
//  lvfj
//
//  Created by lvfeijun on 2021/7/28.
//  Copyright © 2021 Goudu KuaiEx Technology(Shenzhen)Co.,ltd. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN
/**
 一、Realm不支持跨线程访问
 1.跨线程必崩  --  解决方案：用之前，在当前线程从数据库里查
 2.UI的数据必须是用主线程从数据库里查出来的：由于UI都是主现场的 == UI的数据也是主现场的 -- 显示的数据必须用主线程从数据库里查出来
 3.减少主线程消耗：增删可用子线程，之后立马发通知刷新主线程
 4.遵循copy协议，使用copy后的对象，不要直接操作对象
 */

@interface RealmModel : NSObject<NSCopying>

@property (nonatomic, strong) NSString *mid;
@property (nonatomic, assign) NSInteger createTime;

@end

#pragma mark 连表RLMArray：不能设置主键，导致数据重复，需要在一定的时间段自动删除
// 1.RLMArray
//没有主键不能使用addorup，只能使用add 去存

#define kProductPDFDefaultsName @"相关资料"

@interface HQQT_PDFMaterialsModel : RLMObject<CSP_DataModelForDownloadProtocol,BD_TableViewModelProtocal,NSCopying>

@property  (nonatomic, assign) NSInteger useType;
@property  (nonatomic, strong) NSString *downloadUrl;
@property  (nonatomic, assign) NSInteger id;
@property  (nonatomic, strong) NSString *fileName;
@property  (nonatomic, strong) NSString *fileFormat;
@property  (nonatomic, assign) NSInteger size;
@property  (nonatomic, strong) NSString *name;
@property  (nonatomic, strong) NSString *url;

@end
RLM_ARRAY_TYPE(HQQT_PDFMaterialsModel);

@interface HQQT_ProductPDFMaterialsModel : RLMObject<BD_TableViewModelProtocal,NSCopying>

@property  (nonatomic, strong) NSString *name;
@property  (nonatomic, strong) RLMArray <HQQT_PDFMaterialsModel> *materials;

+ (NSArray *)getAllDatas;
@end
RLM_ARRAY_TYPE(HQQT_ProductPDFMaterialsModel);

@interface HQQT_ProductPDFMaterialsArryModel : RLMObject<NSCopying>

@property  (nonatomic, assign) NSInteger goodsId;
//课程资料
@property  (nonatomic, strong) RLMArray <HQQT_ProductPDFMaterialsModel> *materials;
//相关资料
@property  (nonatomic, strong) RLMArray <HQQT_PDFMaterialsModel> *defaults;

+ (instancetype)searchWithGoodsId:(NSInteger)goodsId;
+ (void)saveMaterials:(NSArray <HQQT_ProductPDFMaterialsModel *> *)materials goodsId:(NSInteger)goodsId;
+ (void)saveDefaults:(NSArray <HQQT_PDFMaterialsModel *> *)defaults goodsId:(NSInteger)goodsId;

+ (NSArray *)getAllDatas;

@end
NS_ASSUME_NONNULL_END
